package zhongbo.java.air.dictionary.web.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import zhongbo.java.air.common.vo.PageVo;
import zhongbo.java.air.common.vo.ResultVo;
import zhongbo.java.air.dictionary.model.entities.AirPort;
import zhongbo.java.air.dictionary.service.IAirPortService;

/**
 * 机场相关接口
 *
 * @author WeiJin
 * @version 1.0
 * @date 2025/3/31 12:47
 */
@Api(tags = "机场相关接口")
@RestController
@RequestMapping("/airport")
public class AirPortController {
    @Autowired
    private IAirPortService airPortService;

    /**
     * 保存机场信息到数据库
     *
     * @param airPort 机场信息
     * @return 返回保存的机场信息
     */
    @PostMapping("/add")
    @ApiOperation("保存机场信息")
    public ResultVo<AirPort> saveAirPort(@RequestBody AirPort airPort) {
        AirPort resAirPort = airPortService.saveAirPort(airPort);
        return ResultVo.ok(resAirPort);
    }

    /**
     * 根据机场id删除机场信息
     *
     * @param id 机场id
     * @return 被删除的机场id
     */
    @DeleteMapping("/delete")
    @ApiOperation("删除机场信息")
    public ResultVo<String> delAirPort(String id) {
        String deletedId = airPortService.delAirPort(id);
        return ResultVo.ok(deletedId);
    }

    /**
     * 修改机场信息
     *
     * @param airPort 前端传递过来的修改信息
     * @return 修改后的信息
     */
    @PutMapping("/modify")
    @ApiOperation("修改机场信息")
    public ResultVo<AirPort> modifyAirPort(@RequestBody AirPort airPort) {
        AirPort newAirPort = airPortService.modifyAirPort(airPort);
        return ResultVo.ok(newAirPort);
    }

    /**
     * 根据机场id查询机场信息
     *
     * @param id 机场id
     * @return 机场信息
     */
    @GetMapping("/query")
    @ApiOperation("根据机场id查询机场信息")
    public ResultVo<AirPort> queryAirPort(String id) {
        AirPort airPort = airPortService.queryById(id);
        return ResultVo.ok(airPort);
    }

    /**
     * 分页查询机场信息
     *
     * @param pageNumber 页码
     * @param pageSize   每页记录数
     * @param name       机场全称
     * @param status     状态
     * @param orderBy    排序字段
     * @param orderType  排序类型，true升序 false降序 默认降序
     * @return 机场分页信息
     */
    @GetMapping("/page")
    @ApiOperation("分页查询机场信息")
    public ResultVo<PageVo<AirPort>> pageAirPort(
            @RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
            @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
            @RequestParam(value = "name", required = false) String name,
            @RequestParam(value = "status", required = false) String status,
            @RequestParam(value = "orderBy", required = false) String orderBy,
            @RequestParam(value = "orderType", required = false, defaultValue = "false") Boolean orderType) {
        PageVo<AirPort> airPortPageVo = airPortService.pageAirPort(pageNumber, pageSize, name,
                status, orderBy, orderType);
        return ResultVo.ok(airPortPageVo);
    }
}


